package com.zy.rpc.common.balance.impl;

import com.zy.rpc.common.balance.LoadBalance;
import com.zy.rpc.common.serviceinfo.ServiceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author zy
 * @date 2023/5/25 17:14
 */
public class FullRoundBalance implements LoadBalance {
    private static Logger logger = LoggerFactory.getLogger(FullRoundBalance.class);

    private int index;
    @Override
    public synchronized ServiceInfo choose(List<ServiceInfo> serviceInfoList) {
        // 加锁防止多线程情况下，index超出services.size()
        if (index >= serviceInfoList.size()) {
            index = 0;
        }
        return serviceInfoList.get(index++);
    }
}
